package com.lldpet.spring.cloud.demo.price.service.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.bus.SpringCloudBusClient;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.annotation.Configuration;

/**
 * @desc：PaymentEventListener
 * @author: guanliang.xue
 * @date: 2021/5/10 10:41
 * @version:
 * @since:
 */
@Configuration
public class PaymentEventListener {

    private static final Logger logger = LoggerFactory.getLogger(PaymentEventListener.class);

    @Value("${server.port}")
    private String port;

    /**
     * 监听 paymentEvent 远程事件
     * @param remoteApplicationEvent
     */
    @StreamListener(SpringCloudBusClient.INPUT)
    public void onPaymentRemoteApplicationEvent(RemoteApplicationEvent remoteApplicationEvent){
        // 打印 remoteApplicationEvent 的信息
        logger.info("RemoteApplicationEvent - port: {}, source: {}, originService: {}, destinationService: {}",
                port,remoteApplicationEvent.getSource(),remoteApplicationEvent.getOriginService(),
                remoteApplicationEvent.getDestinationService());
    }
}
